<?php
/**
 * created by zzy
 * date: 2017/10/24 9:28
 */
namespace App\Http\Admin\Company\Controllers;

use App\Eloquent\Ygt\Company;
use Framework\BaseClass\Http\Admin\Controller;

class IndexController extends Controller
{
    public function index(){}
    public function lists(){}
    public function edit()
    {
        $adminUser          = request()->user('admin')->toArray();
        $companyId          = $adminUser['company_id'];
        if (request()->isMethod('post')) {
            $id             = request('id',0);
            $title          = request('title','');
            if(!$title)
            {
                return $this->ajaxFail( '厂名称不能为空' );
            }
            $where          = ['title'=>$title,'id'=>['!=',$id]];
            $info           = Company::getInfo($where);
            if($info)
            {
                return $this->ajaxFail( '厂名称已存在' );
            }
            $data           = request()->all();
            $result         = Company::edit($data);
            if( $result ){
                return $this->ajaxSuccess( '成功' );
            } else {
                return $this->ajaxFail( '失败' );
            }
        } else {
            $where          = ['id'=>$companyId];
            $info           = Company::getInfo($where)->toArray();
            return $this->view('edit', compact('info'));
        }
    }
}